home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1996 #15 / Monster Media Number 15 (Monster Media)(July 1996).ISO / os2 / lxlt113.zip / SOURCES / COUNTRY.PAS < prev    next >
Pascal/Delphi Source File  |  1996-06-05  |  3KB  |  121 lines

  1. {$AlignCode-,AlignData-,AlignRec-,G3+,Speed-,Frame-,FastSelf-}
  2. unit Country;
  3.  
  4. Interface uses use32, os2def, os2base, miscUtil, strOp;
  5.  
  6. const
  7.     cyDefault    = 0; {Use default country}
  8.     cpDefault    = 0; {Use default codepage}
  9.  
  10.   { Option flags for TimeStr }
  11.     toHour       = $01;
  12.     toMinute     = $02;
  13.     toSecond     = $04;
  14.     toHundredths = $08;
  15.     toStdTimeL   = toHour + toMinute + toSecond;
  16.     toStdTimeS   = toHour + toMinute;
  17.  
  18.   { Option flags for DateStr }
  19.     doYear       = $01;
  20.     doMonth      = $02;
  21.     doDay        = $04;
  22.     doDOW        = $08;
  23.     doStdDateL   = doDOW + doYear + doMonth + doDay;
  24.     doStdDateS   = doYear + doMonth + doDay;
  25.  
  26. type
  27.     pCountry = ^tCountry;
  28.     tCountry = object(tObject)
  29.      Info        : CountryInfo;
  30.      constructor Init(Country,CodePage : Word);
  31.      function    DateStr(Options : Word) : string;
  32.      function    TimeStr(Options : Word) : string;
  33.     end;
  34.  
  35. Implementation
  36.  
  37. constructor tCountry.Init;
  38. var cc  : CountryCode;
  39.     len : Longint;
  40. begin
  41.  inherited Init;
  42.  cc.Country := Country;
  43.  cc.CodePage := CodePage;
  44.  if DosQueryCtryInfo(sizeOf(Info), cc, Info, len) <> 0 then Fail;
  45. end;
  46.  
  47. function tCountry.DateStr;
  48. var dt : DateTime;
  49.     S  : string[16];
  50.     I  : Integer;
  51.  
  52. Procedure DateAdd(optMask, Val, Digits : Longint; Sep : Char);
  53. const
  54.     DOWname : array[0..6] of String[3] = ('Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun');
  55. var fst,lst : boolean;
  56. begin
  57.  Delete(S, I, 1);
  58.  if Options and optMask <> 0
  59.   then begin
  60.         if I < length(S) then Insert(Sep, S, I);
  61.         if Digits <> -1
  62.          then Insert(sstr(Val, Digits, '0'), S, I)
  63.          else Insert(DOWname[Val], S, I);
  64.        end;
  65. end;
  66.  
  67. begin
  68.  DosGetDateTime(dt);
  69.  case Info.fsDateFmt of
  70.   0 : S := 'wmdy';
  71.   1 : S := 'wdmy';
  72.   2 : S := 'wymd';
  73.   else S := '';
  74.  end;
  75.  For I := length(S) downto 1 do
  76.   case S[I] of
  77.    'y' : DateAdd(doYear,  dt.Year,    0,  '/');
  78.    'm' : DateAdd(doMonth, dt.Month,   2,  '/');
  79.    'd' : DateAdd(doDay,   dt.Day,     2,  '/');
  80.    'w' : DateAdd(doDOW,   dt.WeekDay, -1, ' ');
  81.   end;
  82.  DateStr := S;
  83. end;
  84.  
  85. function tCountry.TimeStr;
  86. var dt    : DateTime;
  87.     I,V,W : Longint;
  88.     S     : String[16];
  89.     sep   : Char;
  90. begin
  91.  DosGetDateTime(dt);
  92.  S := '';
  93.  For I := 1 to 4 do
  94.   begin
  95.    Sep := ':'; W := 2;
  96.    case I of
  97.     1 : if Options and toHour <> 0
  98.          then V := dt.Hours
  99.          else break;
  100.     2 : if Options and toMinute <> 0
  101.          then V := dt.Minutes
  102.          else break;
  103.     3 : if Options and toSecond <> 0
  104.          then V := dt.Seconds
  105.          else break;
  106.     4 : if Options and toHundredths <> 0
  107.          then begin
  108.                V := dt.Hundredths;
  109.                Sep := '.'; W := 3;
  110.               end
  111.          else break;
  112.    end;
  113.    if S <> '' then Insert(Sep, S, succ(length(S)));
  114.    S := S + sStr(V, W, '0');
  115.   end;
  116.  TimeStr := S;
  117. end;
  118.  
  119. end.
  120.  
  121.